<template>
    <el-form :model="user" label-position="right" label-width="auto">
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="用户名" prop="userName">
                    <el-input v-model="user.userName" placeholder="请输入用户名" clearable/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="密码" prop="pwd">
                    <el-input v-model="user.pwd" placeholder="请输入密码" clearable/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="昵称" prop="nc">
                    <el-input v-model="user.nc" placeholder="请输入昵称" clearable/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="性别" prop="sex">
                    <el-select v-model="user.sex" placeholder="请选择性别">
                        <el-option label="男" value="男"></el-option>
                        <el-option label="女" value="女"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>

        </el-row>
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="手机" prop="phone">
                    <el-input v-model="user.phone" placeholder="请输入手机" clearable/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="邮箱" prop="email">
                    <el-input v-model="user.email" placeholder="请输入邮箱" clearable/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="头像" prop="avatar">
                    <el-input v-model="user.avatar" placeholder="请输入头像" clearable/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="创建时间" prop="createTime">
                    <el-input v-model="user.createTime" placeholder="请输入创建时间" clear/>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="状态" prop="status">
                    <el-select v-model="user.status" placeholder="请选择状态">
                        <el-option label="正常" value="1"></el-option>
                        <el-option label="禁用" value="0"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="店铺数量" prop="shopCount"></el-form-item>
            </el-col>
        </el-row>

    </el-form>

    <el-row>
        <el-col>
            <div style="text-align: center;">
                <el-button type="primary" @click="doSave">保存</el-button>
                <el-button @click="reset">重置</el-button>
            </div>
        </el-col>
    </el-row>
</template>

<script setup lang="ts">
import {ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const user = ref({
    id: '',
    userName: '',
    pwd: '',
    avatar: '',
    nc: '',
    sex: '',
    phone: '',
    createTime: '',
    email: '',
    status: '',
    shopCount: ''
});

const emits = defineEmits(['doList', 'closeDialog']);
const reset = () => {
    user.value = {
        id: '',
        userName: '',
        pwd: '',
        avatar: '',
        nc: '',
        sex: '',
        phone: '',
        createTime: '',
        email: '',
        status: '',
        shopCount: ''
    };
}
const doSave =async () => {
    const {data} = await axios.put('/api/shop/userMS', user.value);
    if (data > 0) {
        emits("doList");				// 触发事件： 刷新页面
        emits("closeDialog");			// 触发事件：关闭 dialog
        ElMessage.success("操作成功！");
    } else {
        ElMessage.error("操作失败！");
    }
}
const handleUpdateData = (obj) => {
    user.value = obj;
}

// 暴露给父组件使用的方法
defineExpose({
    handleUpdateData,
})
</script>

<style scoped>

</style>